package main

import (
	"encoding/json"
	"github.com/1141520944/go-library/hjz/common"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

// SendLogInfo http发送的信息
type SendLogInfo struct {
	Timestamp time.Time `json:"@timestamp"`
	Log       struct {
		Offset int `json:"offset"`
		File   struct {
			Path string `json:"path"`
		} `json:"file"`
	} `json:"log"`
	Message string `json:"message"` // 日志的信息
}

func main() {
	l := common.LoggerDefault("log_collect.log", "./tqLogger")
	e := gin.Default()
	e.GET("/ping", func(c *gin.Context) {
		c.String(200, "ok")
	})
	e.POST("/track/log", func(c *gin.Context) {
		var (
			resp = common.Resp(c)
			req  = new(SendLogInfo)
		)
		if resp.ValidateJson(c, req) {
			indent, _ := json.MarshalIndent(req, "  ", " ")
			println(string(indent))
		}
	})
	srv := &http.Server{Addr: ":8888", Handler: e}
	common.Run(l, srv, nil)
}
